class Animal:
    def __init__(self, name):
        self.name = name

    def get_color(self):
        print("获取动物的颜色")


# 继承Animal
class Dog(Animal):

    Size = "small"

    def __new__(cls, *args, **kwargs):
        print("1.类的创建，首先会走__new__魔术方法", args, "self.size=", cls.Size)
        instance = super().__new__(cls)  # 实际分配空间并返回实例
        return instance

    def __init__(self, name, color):
        print("2.类的创建,走__init__方法")
        super().__init__(name)
        self.name = name
        self.color = color

    def get_color(self):
        super().get_color()
        print("这只狗的颜色为=", self.color)


dog = Dog("husky", "black")

dog.get_color()


class Cat:

    # 重写__new__方法，必须要调用super().__new__(self) ,要不然没法常见该类的实例
    def __new__(self, *args, **kwargs):
        instance = super().__new__(self)
        return instance

    def __init__(self, name):
        self.name = name

    def sound(self):
        print("sound")


cat = Cat("tobo")
cat.sound()
